package com.gui.juc.base.thread.method;


import com.gui.utils.Sleeper;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class InterrupterDemo2 {

    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            log.debug("t1, start...");
            while (true) {
                boolean interrupted = Thread.currentThread().isInterrupted();
                if (interrupted) {
                    log.debug("被打断，停止执行...");
                    break;
                }
            }
            log.debug("t1 finish...");
        }, "t1");
        t1.start();

        Sleeper.sleep(TimeUnit.SECONDS, 1);
        log.debug("interrupt!!!!!");
        t1.interrupt();

    }
}
